;_____________________________________________________________________
;---------------------------------------------------------------------
;	Title: Personal SC Manager
;---------------------------------------------------------------------
;	Group: Overview
;
;		Allows user to view, launch and delete personal shortcuts created
;		through the PM App Launcher <Ctrl+Alt+F9> hotkey.
;
;	Launching:
;		This file is run from the <CWI Search Bar> when the user presses 
;		<Ctrl+F9> while the CWI Search Bar is the active window
;
;	Group: About
;		General script file information
;
;		- *Written By:* 	Rameen Bakhtiary
;		- *Last Modified:*	12/7/2011
;_____________________________________________________________________
;---------------------------------------------------------------------






personalscmanage:

;=================================================================
;                 PERSONAL SC MANAGE RIGHT-CLICK MENU
;=================================================================
menu, rclick, add, Launch, runIT
menu, rclick, add, Show Target, targIT
menu, rclick, add, Delete, delIT



; Right-click menu
;=================
menu, rclick, add, Launch, runIT
menu, rclick, add, Show Target, targIT
menu, rclick, add, Delete, delIT


;===================================================
;							Get shortcut info & show
;===================================================
loop, Personal Links\*
{   listval%a_index% := A_LoopFileFullPath
	FileGetShortcut, %A_LoopFileFullPath%, targ
	if !targ
		targ := A_LoopFileName
	targ%a_index% := targ
	StringReplace, labeln, A_LoopFileName, .lnk,,all
	lval%a_index% := labeln
    if !values
        values := "`t" . labeln
    else
        values .= "|`t" . labeln 
	nrows:=a_index
}
	if !(nrows){
		msgbox, 262192, Personal Shortcut Manager, You you don't have any personal shortcuts saved!`n`nNote - Create personal SC to any program/site by selecting it and pressing <Ctl+Alt+F9>`n
		ExitApp
	}
    gui, 5:+toolwindow
	gui, 5:+alwaysontop
	gui, 5:font,s10 cblue, arial
	gui, 5:Add, ListBox,w230 r%nRows% +AltSubmit vSC gact, %values%
	gui, 5:Show,, Personal Shortcuts
	guicontrol, choose, listbox1, 1
return
;===================================================
;								Double-Click GUI - Run
;===================================================
act:
	if (a_guievent = "doubleclick"){
		gui, 5:submit, nohide
		goto, runit
	}
return
;===================================================
;									Right-Click the  Menu
;===================================================
5guicontextmenu:
	mouseclick
	gui, 5:submit, nohide
	menu, rclick, show
return
;===================================================
;											Run  a shorcut
;===================================================
runit:
	gui, 5:destroy
	fpath := listval%sc%
	run, %fpath%
return
;===================================================
;								Delete  a shortcut
;===================================================
delit:
	thisOne := lval%sc%
	MsgBox, 4148, Are you sure?, Delete `"%thisOne%`" shortcut?
	IfMsgBox, no
		return
	IfMsgBox, yes
	{
		thisone := listval%sc%
		FileDelete, %thisone%
		if errorlevel
			msgbox, Failed to delete
		return
	}
return
;===================================================
;									Show target of shortcut
;===================================================
targIT:
	thisone := lval%sc%
	thisTar := targ%sc%
	msgbox, 4096, SC Info, Label:       %thisone%`n`nTarget: `n           %thistar%
return

GuiEscape:
GuiClose:
gui, 5:destroy
return
